<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    require_once APPPATH . 'libraries/phpQUERY' . EXT;
class Admin extends CI_Controller {
    public  $timecate = 10;
    function __construct()
    {
        parent::__construct();

        $this->load->database();
        $this->load->helper('url');
        $this->load->helper('main_helper');
        $this->load->model('listmail_model');

        $this->load->library('grocery_CRUD');
    }

    function _example_output($output = null)
    {
        $this->load->view('backend/home',$output);
    }

    function offices()
    {
        $output = $this->grocery_crud->render();

        $this->_example_output($output);
    }

    function index()
    {
        $this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
    }

    function category()
    {
        $crud = new grocery_CRUD();

        $crud->set_table('category');
        $crud->columns('name', 'status','position');
        $crud->display_as('name','name category')
             ->display_as('status','status')
             ->display_as('position','position');
        $crud->set_subject('category');
        $crud->required_fields('name','position');
        //$crud->set_relation('name','status','position');
        $output = $crud->render();
        $this->_example_output($output);
    }

    function city() {
        $crud = new grocery_CRUD();
        $crud->set_table('city');
        $crud->required_fields('name','position');

        $output = $crud->render();
        $this->_example_output($output);
    }

    function source() {
        $crud = new grocery_CRUD();

        //$crud->set_theme('datatables');
        $crud->set_table('source');
        $crud->required_fields('name','position');

        $output = $crud->render();
        $this->_example_output($output);
    }

    function product() {
        $crud = new grocery_CRUD();

        $crud->set_table('product');
        $crud->set_relation('cat_id','category','name');
        $crud->set_relation('city_id', 'city', 'name');
        $crud->set_relation('source_id','source','name');
        $crud->set_field_upload('image','assets/uploads/images');
        $crud->set_rules('price','buy Price','numeric');
        $crud->set_rules('orig_price','orig Price','numeric');
        $crud->required_fields('cat_id', 'city_id', 'source_id', 'name', 'description', 'price', 'orig_price', 'start_date', 'exp_date');

        $output = $crud->render();
        $this->_example_output($output);
    }
    function listEmail() {
        $crud = new grocery_CRUD();

        $crud->set_table('mail_schedule');

        $output = $crud->render();
        $this->_example_output($output);
    }
    function viewListEmail() {
        $data = $this->listmail_model->ative();
        echo '<pre>'; var_dump($data); echo '</pre>';
        //getNextHost($data);

        $this->load->view('backend/listmail');
    }
    function getContentWeb() {
        //$this->output->cache($this->timecate);
        $url = 'http://www.hotdeal.vn/ha-noi/an-uong_557';
        $content = get_web_contents($url);
        //echo $content;
        //$html = file_get_contents($url);

        phpQuery::newDocument($content);


        $products = pq('.product_image a');
        foreach($products as $item) {
            $link = 'http://www.hotdeal.vn';
            $link .= pq($item)->attr('href');
            $arrlink[] = $link;



        }
        echo '<pre>';
        var_dump($arrlink);
        echo '</pre>';
        //echo $tagName;
       // echo $childNodes;
        echo '<pre>';
        //pq('.product_image a')->dump();
        echo '</pre>';
        //print $product;
        //echo "<pre>"; var_dump($arrsale);  echo "</pre>";
        //print pq('div.thumb-item.pin-item.col-0 a.link')->attr('title');
        //print pq('div.t-picture-area > a')->attr('href');
        $this->load->view('backend/getcontent');
    }
}